/**
 * Created by Jackie.Chen on 2017/7/28.
 */

var ChangePwd = function () {
    /*基础配置*/
    var el = 'body';

        //修改密码
     function changePwd() {
         if(checkLogin() == false) {
             toLogin();//未登录跳转到登录页面
         } else {
             var oldPassword = $("#oldPassword").val();
             var password = $("#password").val();
             var confirmPassword = $("#confirmPassword").val();
             if (oldPassword === password) {
                 layer.msg('新旧密码不能一致~', {
                     icon: 2,
                     time: 800,
                     shade: 0.2
                 });
                 return;
             }
             if (confirmPassword != password) {
                 layer.msg('确认密码和新密码须一致~', {
                     icon: 2,
                     time: 800,
                     shade: 0.2
                 });
                 return;
             }

             var data = {
                 "oldPassword": oldPassword,
                 "newPassword": password
             };
             ajaxCommonFun({
                 type: 'POST',
                 url: '/user/editPwd.json',
                 data: data,
                 success: function (t) {
                     if (t.status == 'ERROR') {
                         layer.msg(t.message);
                     } else {
                         layer.msg(t.result);
                         location.href = '/user/login.html';
                     }
                 }
             });
         }
     }

    /*页面初始化和事件绑定*/
    function bindEvents() {
        $(el).undelegate()
            .delegate('#submit','click',changePwd);
    }

    /*页面初始化*/
    function init() {
        bindEvents();
    }
    /*end 页面初始化*/
    init();
};

